<?php

namespace app\model\activity\seckill;

use app\model\product\product\StoreProduct;
use app\model\product\sku\StoreProductAttrValue;
use app\model\product\sku\StoreProductStockRelation;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

class StoreSeckillProduct extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'store_seckill_products';

    use ModelTrait;

    // 定义和 zg_store_seckill 表的多对一关系
    public function seckill()
    {
        return $this->belongsTo(StoreSeckill::class, 'seckill_id', 'id');
    }

    public function product()
    {
        return $this->belongsTo(StoreProduct::class, 'product_id', 'id');
    }

    public function attrValue()
    {
        return $this->belongsTo(StoreProductAttrValue::class, 'product_attr_value_unique', 'unique');
    }

    public function stockRelationMap()
    {
        return $this->hasMany(StoreProductStockRelation::class, 'product_id', 'id');
    }
}